package com.sharp.core.graphics;

public final class Color extends UnColor {

	public static Color Random() {
		return new Color((float)Math.random(), (float)Math.random(), (float)Math.random());
	}
	
	public Color() {
	}
	
	public Color(UnColor c) {
		super(c);
	}
	
	public Color(float r, float g, float b) {
		super(r, g, b);
	}
	
	public Color(byte r, byte g, byte b) {
		super(r, g, b);
	}
	
	public final void setTo(UnColor color) {
		this.setTo(color.r, color.g, color.b, color.a);
	}
	
	public final void setTo(int color) {
		this.setTo( ((color>>24)&0xFF)/255.0f, 
					((color>>16)&0xFF)/255.0f,
					((color>>6)&0xFF)/255.0f,
					((color)&0xFF)/255.0f);
	}

	
	public final void setTo(float r, float g, float b) {
		this.r = r;
		this.g = g;
		this.b = b;
	}
	
	public final void setTo(float r, float g, float b, float a) {
		setTo(r, g, b);
		this.a = a;
	}
	
	public Color multiply(UnColor color) {
		this.r *= color.r;
		this.g *= color.g;
		this.b *= color.b;
		this.a *= color.a;
		return this;
	}
	
	public Color multiply(float c) {
		this.r *= c;
		this.g *= c;
		this.b *= c;
		this.a *= c;
		return this;
	}
	
	public Color add(UnColor color) {
		this.r = Math.min(this.r + color.r, 1);
		this.g = Math.min(this.g + color.g, 1);
		this.b = Math.min(this.b + color.b, 1);
		this.a = Math.min(this.a + color.a, 1);
		return this;		
	}
	

	public Color addAndAvg(UnColor color) {
		this.r = (this.r + color.r)/2;
		this.g = (this.g + color.g)/2;
		this.b = (this.b + color.b)/2;
		this.a = (this.a + color.a)/2;
		return this;		
	}
	
	public final void setR(float r) {
		this.r = r;
	}
	public final void setG(float g) {
		this.g = g;
	}
	public final void setB(float b) {
		this.b = b;
	}
	public final void setA(float a) {
		this.a = a;
	}
	
	@Override
	public String toString() {
	    return "(" + r + ", "+ g + ", " + b + ")";
	}
}
